//
//  AnimationExercises.swift
//  NaiCha
//
//  Created by 唐安坤 on 2024/9/2.
//

import SwiftUI

struct AnimationExercises: View {
    @State var progress: CGFloat = 0
    @State var studyColor: Color = .blue
    func getStr(p: CGFloat) -> String{
        return String.init(format: "%.f", p*100)
    }
    var body: some View {
        
        VStack{
            Spacer()
            Circle().stroke(style: StrokeStyle(lineWidth: 25))
                .foregroundColor(.gray.opacity(0.3))
                .frame(width: 300, height: 300, alignment: .center)
                .overlay {
                    
                    ZStack{
                        Circle()
                            .trim(from: /*@START_MENU_TOKEN@*/0.0/*@END_MENU_TOKEN@*/,to: progress)
                            .stroke(style: StrokeStyle(lineWidth: 10,lineCap: .round))
                            .rotationEffect(Angle(degrees:270))
                            .foregroundColor(.green)
                        Text("进度:\(getStr(p: progress))%").foregroundStyle(.gray).font(Font.system(size: 30))
                    }
                    
                        
                }
            
            Spacer()
            
            Button(action: {
                withAnimation(Animation.bouncy(duration: 0.5, extraBounce: 0.3)) {
                    if progress >= 0.99{
                        return
                    }
                    progress += 0.1
                }
            }, label: {
                Text("快！学习！")
                    .padding()
                    .font(Font.system(size: 30))
                    .foregroundStyle(.white)
                    .background(.blue)
                    .cornerRadius(10)
            })
                
            Spacer()
        }
        
    }
}

#Preview {
    AnimationExercises()
}
